#include <bits/stdc++.h>

using namespace std;

/**
 * Definition for a binary tree node.
 */
struct TreeNode {
	int val;
	TreeNode* left;
	TreeNode* right;
	TreeNode(int x)
		: val(x)
		, left(NULL)
		, right(NULL)
	{
	}
};

vector<vector<int>> levelOrder(TreeNode* root);

int main()
{
	return 0;
}

vector<vector<int>> levelOrder(TreeNode* root)
{
	vector<vector<int>> res;
	if (root == NULL) return res;

	queue<TreeNode*> aux;
	vector<int> layer;
	aux.push(root);

	auto last = root;
	while (!aux.empty()) {
		auto pop = aux.front();
		aux.pop();
		layer.emplace_back(pop->val);

		if (pop->left)	aux.push(pop->left);
		if (pop->right)	aux.push(pop->right);

		if (pop == last) {
			res.emplace_back(layer);
			layer.clear();
			last = aux.back();
		}
	}

	return res;
}
